<script setup>
import { queryCustomer } from '@/api/Base/business';
import { queryPurchase } from '@/api/Base/purchase';
import EImage from './EImage.vue';
import { format } from 'date-fns';
import { queryMateriel } from '@/api/Base/repositoryManager';

const show = defineModel("show", {
    default: true
})
const product = defineModel("product", {
    default: {}
})
const selectProduct = reactive({
    name: "",
    list: [],
    reload: () => {
        //TODO:无限屏
        queryMateriel({
            page: 1,
            pageSize: 9999
        }).then(res => {
            if (res.code == 0) {
                selectProduct.list = res.data.list.reverse()
            }
        })
        // queryPurchase({
        //     "page": 1,
        //     "pageSize": 999999999,
        //     "searchKey": "",
        //     "searchProductNo": "",
        //     "startTime": "1993-04-11",
        //     "endTime": "2099-04-22",
        //     "searchType": "",
        //     "searchStatus": 0
        // }).then(res => {
        //     if (res.code == 0) {
        //         selectPurchase.list = res.data.list.reverse()
        //     }
        // })
    }
})

onMounted(() => {
    selectProduct.reload()
})
</script>

<template>
    <van-popup class="h-50vh flex flex-col gap-10" teleport="#app" v-model:show="show" round position="bottom">
        <van-search @search="selectProduct.reload" @cancel="selectProduct.list = []" v-model="selectProduct.name"
            placeholder="请输入物料关键字" />
            <div class="h-[100%] flex flex-col gap-10 overflow-y-scroll bg-[#f2f4f8] p-10 w-100% rounded-[10px]">

            <div class="border bg-white gap-10 rounded-[10px] p-10 flex" v-for="(item, index) in selectProduct.list"
                :key="index">
                <!-- {{ item }} -->
                <van-checkbox @click="() => {
                    product = item
                    show = false
                }" class="rounded-full"></van-checkbox>
                <EImage :width="'100px'" :photo-url="item.sPhotoUrl" />
                <div>
                    <h1 class="text-[14px] leading-[0px] mx-0 text">
                        {{ JSON.parse(item.sProductClass).join(",") + JSON.parse(item.sProductPublicClass).join(",") +
                            item.sProductName }}
                    </h1>
                    <div class="flex items-center gap-10">
                        <h1 class="text-[10px] text-coolgray leading-none">料号:{{ item.sProductNo }}</h1>
                        <h1 class="text-[10px] text-coolgray leading-none">推荐等级:{{ item.sRecommendGrade }}</h1>
                        <h1 class="w-[100%] text-right text-coolgray text-[10px] leading-none">库存{{
                            item.effectiveQuantity }}</h1>
                    </div>
                </div>
            </div>

        </div>
    </van-popup>
</template>
<style lang="less"></style>